﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;

namespace QLKTX1._0.DAO
{
    class ValidateData
    {

        // kiem tra 1 gia tri da ton tai trong csdl chua
        /*
          namTable: ten table can kiem tra
         * nameCol: ten truong can kiem tra
         * value: gia tri can kiem tra
         * 
         * return :
         * 
         * true: gia tri da ton tai
         * false: gia tri chua ton tai
         
         */
        public static bool checkDataExistabled(string nameTable,string nameCol,string value)
        {           

            ConnectDB con = new ConnectDB();

            string sql = "SELECT count(" + nameCol + ") as kq FROM " + nameTable + " WHERE " + nameCol + "='" + value + "'";

            DataTable dt = con.getDataTable(sql);
       
            if (Int32.Parse(dt.Rows[0]["kq"].ToString()) >= 1)//Du lieu co ton tai ko
            {
                 return true;
            }          
           
            return false;
        }
    }
}
